import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import TabbarHome from '@/views/TabbarPages/TabbarHome.vue'
import store, { StateAll } from '@/store/index'


const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Tabbar',
    component: TabbarHome,
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('@/views/TabbarPages/Home/index.vue')
      },
      {
        path: 'node',
        name: 'Node',
        component: () => import('@/views/TabbarPages/Node/routerIndex.vue'),
        children: [
          {
            path: '',
            name: 'Nodex',
            component: () => import('@/views/TabbarPages/Node/index.vue'),
          },
          {
            path: 'nodelist',
            name: 'NodeList',
            component: () => import('@/views/TabbarPages/Node/components/NodeList.vue')
          },
          {
            path: 'achievement',
            name: 'Achievement',
            component: () => import('@/views/TabbarPages/Node/components/Achievement.vue')
          },
          {
            path: 'recommendlist',
            name: 'RecommendList',
            component: () => import('@/views/TabbarPages/Node/components/RecommendList.vue')
          },
        ]
      },
      {
        path: 'strategy',
        name: 'Strategy',
        component: () => import('@/views/TabbarPages/Strategy/routerIndex.vue'),
        children: [
          {
            path: '',
            name: 'Nodex2',
            component: () => import('@/views/TabbarPages/Strategy/index.vue'),
          },
          {
            path: 'aidetail',
            name: 'AiDetail',
            component: () => import('@/views/TabbarPages/Strategy/components/AiDetail.vue'),
          }
        ]
      },
      {
        path: 'actical',
        name: 'Actical',
        component: () => import('@/views/TabbarPages/Actical/index.vue')
      },
      {
        path: 'capital',
        name: 'Capital',
        component: () => import('@/views/TabbarPages/Capital/routerIndex.vue'),
        children: [
          {
            path: '',
            name: 'Nodex3',
            component: () => import('@/views/TabbarPages/Capital/index.vue'),
          },
          {
            path: 'recharge',
            name: 'Recharge',
            component: () => import('@/views/TabbarPages/Capital/components/Recharge.vue'),
          },
          {
            path: 'withdrawal',
            name: 'Withdrawal',
            component: () => import('@/views/TabbarPages/Capital/components/Withdrawal.vue'),
          },
          {
            path: 'confirmwithdrawal',
            name: 'ConfirmWithdrawal',
            component: () => import('@/views/TabbarPages/Capital/components/ConfirmWithdrawal.vue'),
          },
          {
            path: 'transfer',
            name: 'Transfer',
            component: () => import('@/views/TabbarPages/Capital/components/Transfer.vue'),
          },
          {
            path: 'transfer2',
            name: 'Transfer2',
            component: () => import('@/views/TabbarPages/Capital/components/Transfer2.vue'),
          },
          {
            path: 'transfertrue',
            name: 'Transfertrue',
            component: () => import('@/views/TabbarPages/Capital/components/TransferTrue.vue'),
          },
        ]
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/User/Login.vue')
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('@/views/User/Register.vue')
  },
  {
    path: '/zapi',
    name: 'Api',
    component: () => import('@/views/Options/Api/index.vue')
  },
  {
    path: '/editemail',
    name: 'EditEmail',
    component: () => import('@/views/Options/EditEmail/index.vue')
  },
  {
    path: '/editaddress',
    name: 'EditAddress',
    component: () => import('@/views/Options/EditAddress/index.vue')
  },
  {
    path: '/editpass',
    name: 'EditPass',
    component: () => import('@/views/Options/EditPass/index.vue')
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('@/views/Options/About/index.vue')
  },
  {
    path: '/share',
    name: 'Share',
    component: () => import('@/views/Options/Share/index.vue')
  },
  {
    path: '/acticaldetail',
    name: 'ActicalDetail',
    component: () => import('@/views/Options/ActicalDetail/index.vue')
  },
  {
    path: '/noticelist',
    name: 'NoticeList',
    component: () => import('@/views/Options/NoticeList/index.vue')
  },
  {
    path: '/webview',
    name: 'Webview',
    component: () => import('@/views/Options/Webview/index.vue')
  }
]

const router = createRouter({
  scrollBehavior: () => {
    return { top: 0 ,behavior:'smooth'}
  },
  history: createWebHistory(process.env.BASE_URL),
  routes
})



router.beforeEach((to, from, next) => {
  const token = (store.state as StateAll).users.token
  const infos = (store.state as StateAll).users.infos
  // store.dispatch('users/check')
  next()
  // if (token || to.fullPath.includes('/login')) {
  //   if (token && !infos.email) {
  //     store.dispatch('users/updateUserInfo')
  //   }
  //   next()
  // } else {
  //   next('/login')
  // }
})

export default router
